/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;
import java.util.Date;

/**
 *
 * @author Stratos
 */
public class TicketMachine {
    
    String stationName;
    Integer id;
    Integer regulars;
    Integer students;
    Integer soldiers;
    Double income;
    Date date;
    
    public TicketMachine(String stationName, Integer id) {
        this.stationName = stationName;
        this.id = id;
        
    }

    public Card createCard(Passenger p) {
        Double price = new Double(0.0);
        String type = p.getType();
        if (type.equalsIgnoreCase("Regular")) {
            price = 0.8 * 60;

        } else if (type.equalsIgnoreCase("Student")) {
            price = 0.8 * 60 * 0.5;
        }
        Card card = new Card();
        card.setPrice(price);

        return card;

    }

    public Card createCard(Passenger p, Double factor, Double fullPrice, Double ticketPrice) {
        Double price = new Double(0.0);
        String type = p.getType();
        if (type.equalsIgnoreCase("Regular")) {
            price = factor * fullPrice * ticketPrice;

        } else if (type.equalsIgnoreCase("Student")) {
            price = factor * fullPrice * ticketPrice * 0.5;
        }
        Card card = new Card();
        card.setPrice(price);

        return card;

    }

    public Double giveCard(Passenger p) {
        Card card = createCard(p);
        p.setCard(card);

        return card.getPrice();
    }

    public void checkIn(Passenger p) {
        String type = p.getType();
        System.out.println("Type = " + type);
        if (type.equalsIgnoreCase("Regular")) {
            regulars++;
            if (p.hasCard()) {
            } else {
                if (p.wantsCard) {
                    //ticketNo++;
                    Double cardPrice = giveCard(p);
                    income = income + cardPrice;
                    System.out.println("[" + date.getTime() + " - " + this.stationName
                            + " - " + this.id + "]" + "Έκδοση μηνιαίας κάρτας - "
                            + cardPrice + " ευρώ");
                } else {
                    //ticketNo++;
                    income = income + 1;
                    System.out.println("[" + date.getTime() + " - " + this.stationName
                            + " - " + this.id + "]" + "Έκδοση εισιτηρίου - 1 ευρώ");
                }
            }
        } else if (type.equalsIgnoreCase("Student")) {
            students++;
            if (p.hasCard()) {
            } else {
                if (p.wantsCard) {
                    //ticketNo++;
                    Double cardPrice = giveCard(p);
                    income = income + cardPrice;
                    System.out.println("[" + date.getTime() + " - " + this.stationName
                            + " - " + this.id + "]" + "Έκδοση μηνιαίας κάρτας - "
                            + cardPrice + " ευρώ");
                } else {
                    //ticketNo++;
                    income = income + 0.5;
                    System.out.println("[" + date.getTime() + " - " + this.stationName
                            + " - " + this.id + "]" + "Έκδοση εισιτηρίου - 0.5 ευρώ");
                }
            }
        } else if (type.equalsIgnoreCase("Soldier")) {
            soldiers++;
        }

    }
}
